package com.hzhk.happyrent.utils;

import android.app.Activity;
import android.content.Context;
import android.view.Display;
import android.view.WindowManager;

/**
 * dip与px之间的转化
 *
 * @author
 */
public class DensityUtil {
	/**
	 * dip 转换成 px
	 *
	 * @param context
	 * @param dpValue
	 * @return
	 */
	public static int dip2px(Context context, float dpValue) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (dpValue * scale + 0.5f);
	}
	
	/**
	 * px 转换成 dip
	 *
	 * @param context
	 * @param pxValue
	 * @return
	 */
	public static int px2dip(Context context, float pxValue) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (pxValue / scale + 0.5f);
	}
	
	public static int getScreenWidth(Activity context) {
		WindowManager windowManager = context.getWindowManager();
		Display display = windowManager.getDefaultDisplay();
		return display.getWidth();
	}
}
